﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD;
using Xunit;

namespace DokiDokiTest {

    public class TestComponent {

        [Fact]
        public void Test_New1 () {
            var cmp = (Component)new Mesh ();

            Assert.Equal (null, cmp.Node);
        }

        [Fact]
        public void Test_Attach () {
            var cmp = (Component)new Mesh ();
            var nod = new Node ();
            nod.Attach (cmp);

            Assert.Equal (nod, cmp.Node);
        }

        [Fact]
        public void Test_Detach () {
            var cmp = (Component)new Mesh ();
            var nod = new Node ();
            nod.Attach (cmp);
            nod.Detach (cmp);

            Assert.Equal (null, cmp.Node);
        }

        [Fact]
        public void Test_SendMessage1 () {
            var cmp1 = (Component)new Mesh ();
            var nod1 = new Node ();
            nod1.Attach (cmp1);

            var cmp2 = new MyTestComponent ();
            var nod2 = new Node ();
            nod2.Attach (cmp2);

            cmp1.SendMessage (nod2, "Set1");

            Assert.Equal (1, cmp2.Value);
        }

        [Fact]
        public void Test_SendMessage2 () {
            var cmp1 = (Component)new Mesh ();
            var nod1 = new Node ();
            nod1.Attach (cmp1);

            var cmp2 = new MyTestComponent ();
            var nod2 = new Node ();
            nod2.Attach (cmp2);

            cmp1.SendMessage (nod2, "Set", 2);

            Assert.Equal (2, cmp2.Value);
        }

        [Fact]
        public void Test_SendMessage3 () {
            var cmp1 = (Component)new Mesh ();
            var nod1 = new Node ();
            nod1.Attach (cmp1);

            var cmp2 = new MyTestComponent ();
            var nod2 = new Node ();
            nod2.Attach (cmp2);

            cmp1.SendMessage<MyTestComponent> (nod2, "Set1");

            Assert.Equal (1, cmp2.Value);
        }

        [Fact]
        public void Test_SendMessage4 () {
            var cmp1 = (Component)new Mesh ();
            var nod1 = new Node ();
            nod1.Attach (cmp1);

            var cmp2 = new MyTestComponent ();
            var nod2 = new Node ();
            nod2.Attach (cmp2);

            cmp1.SendMessage<MyTestComponent, int> (nod2, "Set", 2);

            Assert.Equal (2, cmp2.Value);
        }

        [Fact]
        public void Test_References () {
            var cmp = (Component)new Mesh ();
            var nod = new Node ();
            nod.Attach (cmp);

            var objs = cmp.References;

            Assert.Equal (0, objs.Count ());
        }

        [Fact]
        public void Test_Find () {
            var cmp = (Component)new Mesh ();
            var nod = new Node ();
            nod.Attach (cmp);

            cmp.UserID = 101;

            Assert.Equal (cmp, cmp.Find (101));
            Assert.Equal (cmp, nod.Find (101));
        }

    }
}
